export default {
    data() {
        return {
            beginX: null,
            beginY: null,
            startx: null,
            beginTwoX: null,
            beginTwoY: null,
            startTwox: null,
            count: 0,
            top: 0,
        }
    },
    computed: {},
    mounted() {

    },
    beforeUnmount() {
        this.removeWetherScroll();
    },
    methods: {
        // 移动端横屏滑动方向
        wetherScroll() {
            let that = this
            var ele = document.getElementsByClassName("Nrotate2")[1] || document.getElementsByClassName("TableY")[1];
            ele.addEventListener('touchstart', that.start);
            ele.addEventListener('touchmove', that.content);

        },
        tableFunc() {
            let that = this
            var table = document.getElementsByClassName("q-table__middle")[1] || document.getElementsByClassName("q-markup-table")[1];
            table.addEventListener('touchstart', that.tableStart);
            table.addEventListener('touchmove', that.tableContent);

        },
        removeWetherScroll() {
            let that = this
            var ele = document.getElementsByClassName("Nrotate2")[1] || document.getElementsByClassName("TableY")[1];
            var table = document.getElementsByClassName("q-table__middle")[1] || document.getElementsByClassName("q-markup-table")[1];
            if (ele != undefined) {
                ele.removeEventListener('touchstart', that.start);
                ele.removeEventListener('touchmove', that.content);
            }
            if (table != undefined) {
                table.style.overflow = 'auto'
                table.removeEventListener('touchstart', that.tableStart);
                table.removeEventListener('touchmove', that.tableContent);
            }
        },
        start(e) {
            var ele = document.getElementsByClassName("Nrotate2")[1] || document.getElementsByClassName("TableY")[1];
            this.beginX = e.targetTouches[0].clientX;
            this.beginY = e.targetTouches[0].clientY;
            this.top = ele.scrollTop
            this.count++
        },
        content(e) {
            let that = this
            var ele = document.getElementsByClassName("Nrotate2")[1] || document.getElementsByClassName("TableY")[1];
            var table = document.getElementsByClassName("q-table__middle")[1] || document.getElementsByClassName("q-markup-table")[1];
            var endX, endY, endx2;
            endX = e.targetTouches[0].clientX;
            endY = e.targetTouches[0].clientY;
            // 左右滑动
            if (Math.abs(endX - this.beginX) - Math.abs(endY - this.beginY) > 0) {
                table.style.overflow = 'hidden'
                endx2 = e.targetTouches[0].clientX;
                /*向右滑动*/
                if (endX - this.beginX > 0) {
                    if (this.count < 2) {
                        ele.scrollTop = endx2 - this.beginX
                    } else {
                        ele.scrollTop = this.top + (endx2 - this.beginX)
                    }
                }
                /*向左滑动*/
                else {
                    this.count = 0
                    ele.scrollTop = this.top - (this.beginX - endx2)
                }
            } else if (Math.abs(endX - this.beginX) - Math.abs(endY - this.beginY) < 0) {
                table.style.overflow = 'auto'
                that.tableFunc();
            }
        },
        tableStart(e) {
            this.beginTwoX = e.targetTouches[0].screenX;
            this.beginTwoY = e.targetTouches[0].screenY;
        },
        tableContent(e) {
            var endX, endY
            var table = document.getElementsByClassName("q-table__middle")[1] || document.getElementsByClassName("q-markup-table")[1];
            var Nrotate2 = document.getElementsByClassName("TableY")[1] || document.getElementsByClassName("Nrotate2")[1];
            endX = e.targetTouches[0].screenX;
            endY = e.targetTouches[0].screenY;
            if (Math.abs(endX - this.beginTwoX) - Math.abs(endY - this.beginTwoY) < 0) {
                e.stopPropagation()
                table.style.overflow = 'auto'
                Nrotate2.style.overflow = 'hidden'
                    /*向右滑动*/
                if (endY - this.beginTwoY > 0) {
                    table.scrollLeft = parseInt(table.scrollLeft) - 10
                }
                /*向左滑动*/
                else {
                    table.scrollLeft = parseInt(table.scrollLeft) + 10
                }
            } else if (Math.abs(endX - this.beginTwoX) - Math.abs(endY - this.beginTwoY) > 0) {
                Nrotate2.style.overflow = 'scroll'
                table.style.overflow = 'hidden'
            }
        },
    }
}